package com.xsmart.oa.api;

import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.oa.services.ServiceListCtrlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 服务列表管理
 *
 * @author guojd
 */
@RestController
@RequestMapping("/api")
public class ServiceListCtrlController {
    @Autowired
    ServiceListCtrlService serviceListCtrlService;

    /**
     * 缓存同步api到数据库
     * @param requestBean
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/ServiceListCtrlService/synApiCacheToDb")
    public ResponseBean synApiCacheToDb(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return serviceListCtrlService.synApiCacheToDb(requestBean, request);
    }

    /**
     * 数据库同步api到缓存
     * @param requestBean
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/ServiceListCtrlService/synApiDbToCache")
    public ResponseBean synApiDbToCache(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return serviceListCtrlService.synApiDbToCache(requestBean, request);
    }

    /**
     * 获取api列表
     * @param requestBean
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/ServiceListCtrlService/getApiInfoList")
    public ResponseBean queryServiceList(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return serviceListCtrlService.queryServiceList(requestBean, request);
    }

    /**
     * 新增服务接口api
     * @param requestBean
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/ServiceListCtrlService/addServiceList")
    public ResponseBean addServiceList(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return serviceListCtrlService.addServiceList(requestBean, request);
    }

    /**
     * 修改服务接口api
     * @param requestBean
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/ServiceListCtrlService/modServiceList")
    public ResponseBean modServiceList(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return serviceListCtrlService.modServiceList(requestBean, request);
    }

    /**
     * 删除服务接口api
     * @param requestBean
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/ServiceListCtrlService/delServiceList")
    public ResponseBean delServiceList(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return serviceListCtrlService.delServiceList(requestBean, request);
    }

    /**
     * 清空api缓存
     * @param requestBean
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/ServiceListCtrlService/delCache")
    public ResponseBean delCache(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return serviceListCtrlService.delCache(requestBean, request);
    }
}
